
$(document).ready(function()
{
	$('.comment_like_up').unbind('click').click(function(){ upLike($(this).attr('id').replace('link_like_', '')); return false;	});
	$('.comment_dislike_up').unbind('click').click(function(){ upDislike($(this).attr('id').replace('link_dislike_', '')); return false; });
	$('.comment_delete').unbind('click').click(function(){ commentDelete($(this).attr('id')); return false;	});
});

function commentDelete(id)
{
	if (confirm("Are you sure you want to delete")) {
		$.ajax({
			type: 'GET',
			url: baseDir + 'modules/reviewratingsynthesis/reviewratingsynthesis-ajax.php',
			async: true,
			data: 'ajax=true&deteteComment=1&id='+id+'&token='+static_token,
			success: function(data) {
				$('#li_header_comment_'+data).remove();
				$('#li_comment_'+data).remove();
				$('#li_comment_admin_'+data).remove();
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to save delete comment \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);}
		});
	}
}

function upLike(id)
{
	$.ajax({
		type: 'GET',
		url: baseDir + 'modules/reviewratingsynthesis/reviewratingsynthesis-ajax.php',
		async: true,
		data: 'ajax=true&vote=like&id='+id+'&token='+static_token,
		success: function(data) {
			if(data != 'error')
				if(data == 'a'){
					$("#popup-vote-already").show().dialog("open");
				} else if(data=='b'){
					$("#popup-vote-already").show().dialog("open");
				} else if(data=='notLogged'){
					$("#popup-vote-notLogged").show().dialog("open");
				} else{
					$('#number_like_'+id).html(data);
					$("#popup-vote-success").show().dialog("open");
				}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to save update vote \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);}
	});
}

function upDislike(id)
{
	$.ajax({
		type: 'GET',
		url: baseDir + 'modules/reviewratingsynthesis/reviewratingsynthesis-ajax.php',
		async: true,
		data: 'ajax=true&vote=dislike&id='+id+'&token='+static_token,
		success: function(data) {
			if(data != 'error'){
				if(data == 'a'){
					$("#popup-vote-already").show().dialog("open");
				} else if(data == 'b'){
					$("#popup-vote-already").show().dialog("open");
				} else if(data=='notLogged'){
					$("#popup-vote-notLogged").show().dialog("open");
				} else{
					$('#number_dislike_'+id).html(data);
					$("#popup-vote-success").show().dialog("open");
				}
			}
				
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to save update vote \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);}
	});
}